package metrictree.trees;

public class Pair<K extends Comparable,V> implements Comparable<Pair<K, V>>{
	private final K key;
	private final V value;
	
	public Pair(K first, V second) {
		this.key  = first;
		this.value = second;
	}
	
	public K getKey() {
		return key;
	}
	
	public V getValue() {
		return value;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Pair))
			return false;
		Pair other = (Pair) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
	

	
	public String toString() {
		//return String.format("{:FIRST %s :SECOND %s}", key, value);
		return String.format("{%s}",key);
	}

	
	@Override
	public int compareTo(Pair<K, V> o) {
		return this.getKey().compareTo(o.getKey());
	}
	
	
}
